home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / doslynx / src / tdosly13.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  3.2 KB  |  93 lines

  1. //    Copyright (c) 1994, University of Kansas, All Rights Reserved
  2. //
  3. //    Class:        TDosLynx
  4. //    Include File:    tdoslynx.h
  5. //    Purpose:    Provide the application for a WWW client.
  6. //    Remarks/Portability/Dependencies/Restrictions:
  7. //    Revision History:
  8. //        02-25-94    created
  9. #include"tdoslynx.h"
  10. #include"trace.h"
  11. #include"globals.h"
  12. #include"gridtext.h"
  13. #include<dos.h>
  14.  
  15. extern void ReleaseSomeMemory()    {
  16. //    Purpose:    operator new failure correction function.
  17. //    Arguments:    void
  18. //    Return Value:    void
  19. //    Remarks/Portability/Dependencies/Restrictions:
  20. //        This function is registered to be the new handler in the
  21. //        TDosLynx constructor.  This function will be called when the
  22. //        operator new fails to allocate memory.
  23. //        All this function attempts to do is release already used
  24. //        memory that is not being utilized at the moment in order
  25. //        to allow more allocation to take place.  If this is unable
  26. //        to be accomplished, then this function must take action and
  27. //        exit the program;  will be in fact handled by the previous
  28. //        memory handler if one existed before this one was registered.
  29. //        Don't, whatever you do, include capalloc.h from the DosLynx
  30. //        project.  You will cause the memory pools to free, and then
  31. //        reallocate themselves really doing nothing.
  32. //    Revision History:
  33. //        02-25-94    created to enhance DosLynx memory management.
  34. //        03-13-94    Modified to exit the program without further
  35. //                attempting cleanup by sending messages through
  36. //                TurboVision.
  37.  
  38.     //    Our job, release the first unused unloading HText in our
  39.     //    list and free it.  If none exist, call the old new handler.
  40.     //    If it doesn't exist, terminate the program.
  41. #ifndef RELEASE
  42.     trace("Attempting to find memory to release.");
  43. #endif // RELEASE
  44.  
  45.     //    Loop through all HText entries.
  46.     HText *HTp_remove;
  47.     signed short int ssi_search;
  48.     for(ssi_search = 0; ssi_search < TNSCp_LoadedHTexts->getCount();
  49.         ssi_search++)    {
  50.         HTp_remove = (HText *)(TNSCp_LoadedHTexts->
  51.             at(ssi_search));
  52.         //    If the HText is being used by a view or is being
  53.         //    loaded, cannot destroy it; continue.
  54.         if(HTp_remove->usi_Views != 0U)
  55.             continue;
  56.         else if(HTp_remove->B_isLoading == True)
  57.             continue;
  58.  
  59.         //    An open HText found, free it, it's anchors and quit
  60.         //    the loop.
  61.         HText_free(HTp_remove);
  62.         return;
  63.     }
  64.  
  65.     //    We have reached a point to begin deallocating the really
  66.     //    safe pool.  All other memory at this point should have
  67.     //    been released that possible could have.
  68.     for(register signed short int ssi_counter = Stop_Anchors; ssi_counter
  69.         < RSP_NUM; ssi_counter++)    {
  70.         //    See if we found one to release.
  71.         if(really_safe_pool[ssi_counter] != NULL)    {
  72.             //    Can release.  Do so.
  73.             free(really_safe_pool[ssi_counter]);
  74.             really_safe_pool[ssi_counter] = NULL;
  75.             return;
  76.         }
  77.     }
  78.  
  79.     //    Modified not to call the old handler, since will simply
  80.     //    terminate the program.  Will try to display a message
  81.     //    and cleanup below.
  82.  
  83.     //    We have to exit the program in a very ugly way.
  84.     //    Try to tell the user that we are sorry.
  85.     doslynxmessage("All attempts to allocate more memory have failed.");
  86.     doslynxmessage("Program Terminating....");
  87.  
  88.     //    give the user time to see the message.
  89.     sleep(5);
  90.  
  91.     //    Exit the application.
  92.     exit(1);
  93. }